package jp.co.neosystem.adwg.neodiary.view.listview.adapter;

import java.util.List;

import jp.co.neosystem.adwg.neodiary.R;
import jp.co.neosystem.adwg.neodiary.view.listview.bean.SearchResultListBean;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 検索結果用リストビューアダプタ
 * 
 * @author NEOSystem
 */
public class SearchResultListAdapter extends BaseAdapter
{
	@SuppressWarnings("unused")
	private Context context;
	private List<SearchResultListBean> list;
	private LayoutInflater layoutInflater;

	/**
	 * コンストラクタ
	 * 
	 * 
	 */
	public SearchResultListAdapter(Context context, List<SearchResultListBean> list)
	{
		this.context = context;
		this.list = list;
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	/**
	 * リストビューの件数を取得
	 * 
	 * @return リストビューの件数
	 */
	public int getCount()
	{
		return list.size();
	}

	/**
	 * リストビューのアイテムを取得
	 * 
	 * @param position
	 */
	public Object getItem(int position)
	{
		return list.get(position);
	}

	/**
	 * リストビューのアイテムIDを取得
	 * 
	 * @param position
	 */
	public long getItemId(int position)
	{
		return position;
	}

	/**
	 * 
	 * @param position
	 * @param convertView
	 * @param parent
	 */
	public View getView(int position, View convertView, ViewGroup parent)
	{
		SearchResultListBean bean = (SearchResultListBean) getItem(position);
		convertView = layoutInflater.inflate(R.layout.listview_search_result, null);
		
		TextView textViewDate = (TextView) convertView.findViewById(R.id.listview_search_result_date);
		TextView textViewTitle = (TextView) convertView.findViewById(R.id.listview_search_result_title);
		textViewDate.setText(bean.getDate());
		textViewTitle.setText(bean.getTitle());
		
		return convertView;
	}
}
